package com.zyj.myapplication.Fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zyj.myapplication.Adapter.ClubInfoAdapter;
import com.zyj.myapplication.Javabean.Club;
import com.zyj.myapplication.Model.ClubModel;
import com.zyj.myapplication.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


public class CIntroFragment extends Fragment {
    private RecyclerView recyclerView;
    private Club clubinfo;
    private List<Club.ClubteacherEntity> Data;
    private TextView clubinfoContent, cintro_adress, cintro_phone, cintro_time;
    private String club_id;
    private View view = null;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_cintro, container, false);
        initViews();//初始化
        initEvents();//初始化事件
        showData();
        return view;
    }

    private void initViews() {
        recyclerView = (RecyclerView) view.findViewById(R.id.clubinfo_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        clubinfoContent = (TextView) view.findViewById(R.id.clubinfoContent);
        cintro_adress = (TextView) view.findViewById(R.id.cintro_adress);
        cintro_phone = (TextView) view.findViewById(R.id.cintro_phone);
        cintro_time = (TextView) view.findViewById(R.id.cintro_time);
    }

    private void initEvents() {
        Intent intent = getActivity().getIntent();
        club_id = intent.getStringExtra("club_id");
    }

    private void showData() {
        ClubModel clubModel = new ClubModel();
        Call<Club> call = clubModel.getClubInfo(club_id);
        call.enqueue(new Callback<Club>() {
            @Override
            public void onResponse(Call<Club> call, Response<Club> response) {
                clubinfo = response.body();
                if (clubinfo.getIntroduction().equals("null")) {
                    clubinfoContent.setText("如果你无法简介的表达你的想法那只能说明你还不够了解他！！！");
                } else {
                    clubinfoContent.setText(clubinfo.getIntroduction());
                }
                if (clubinfo.getDistrict_name().equals("")) {
                    cintro_adress.setText("大连市甘井子区");
                } else {
                    cintro_adress.setText(clubinfo.getDistrict_name());
                }
                if (clubinfo.getClub_tel().equals("")) {
                    cintro_phone.setText("0411-575986960");
                } else {
                    cintro_phone.setText(clubinfo.getClub_tel());
                }
                if (clubinfo.getOpen_time().equals("")) {
                    cintro_time.setText("10:00-22:00");
                } else {
                    cintro_time.setText(clubinfo.getOpen_time());
                }

                Data = response.body().getClubteacher();
                recyclerView.setAdapter(new ClubInfoAdapter(getActivity(), Data));
            }

            @Override
            public void onFailure(Call<Club> call, Throwable t) {

            }
        });
    }
}
